<?php 
include_once 'functions.php';

////////////////////////////////////////////////////////////////////////////////////////
//																				FEEDBACK 
////////////////////////////////////////////////////////////////////////////////////////
	$resultsFeedback= "You have not attempted this test";
if ($_SESSION['score'] <= 5) {
     $resultsFeedback = "You have less than 5, you should...";
}
if ($_SESSION['score'] > 6 && $_SESSION['score'] < 9){
    $resultsFeedback = "You have between 5 and 8, you should...";
}
if ($_SESSION['score'] >8){
       $resultsFeedback = "You have more than 9, you should...";
}
if (!$_SESSION['score']){
       $resultsFeedback = "You have not attempted this test...";
}
////////////////////////////////////////////////////////////////////////////////////////
//																		   TEST FEEDBACK
////////////////////////////////////////////////////////////////////////////////////////
$con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);   
$query = "SELECT * FROM studentresponse WHERE testID = "
. "'" . $testID . "'"
.  " AND studentID =" 
. "'".  $_SESSION['studentID'] . "'"
.  " AND attempt = 2";
$result = mysqli_query($con, $query);
if ($result)
  {
	$numberOfRows = mysqli_num_rows($result);
	if ($numberOfRows > 0) 
	{
	$rowContent= array();
	while ($row = mysqli_fetch_array($result))
	 {
	$rowContent[] = $row;

		}
	} 
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="styles/styles.css" type="text/css" />
<title>Results</title>
</head>
<body>
<div id="header"> </div>
<div id="container">
  <div id="mainContent">
  <header>
<nav>
<?php include 'nav.php' ?>
</nav>

</header>  <h1>Feedback</h1>
      <h2>You scored
        <?php echo $_SESSION['score']?>
        /10</h2>
      <progress max="10" value="<?php echo $_SESSION['score']?>"></progress>
      <p>
        <?php echo $resultsFeedback ?>
      </p>
      <?php
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,$query);
	$selectedAnswer = $rowContent[0][3];
		$correctAnswer = $rowContent[0][4];
for ($row = 0; $row < 10; $row++)
  {
  echo "<h2>Question ";
  echo $row+1;
  echo "</h2>";
  for ($col = 3; $col < 4; $col++)
    {
		$selectedAnswer = $rowContent[$row][$col];
    echo "<p>You said: ".$rowContent[$row][$col]."</p>";
    }
	for ($col = 4; $col < 5; $col++)
    {
    $correctAnswer = $rowContent[$row][$col];
    }
 if ($selectedAnswer == $correctAnswer) {
		
		$feedbackStatus = "<span class='green'>You were correct.</span>";
        } 
				else {
        $feedbackStatus = "<span class='red'>You were incorrect,</span> the correct answer was $correctAnswer.";
		} 
		echo $feedbackStatus;
  }
	?>
    </div>
    
      <p class='smiling'>Incorrect Answers:
        <?php echo print_r(array_values($_SESSION['incorrect']))?>
      </p>
      <p class='smiling'>Correct Answers:
        <?php echo print_r(array_values($_SESSION['correct']))?>
      </p>
      <p class='smiling'>Selected Answers:
        <?php echo $selectedAnswer ?>
      </p>
      <p class='smiling'>Score:
        <?php echo $score ?>
      </p>
      <p class='smiling'>Num:
        <?php echo $num ?>
      </p>
      <p class='smiling'>Last:
        <?php echo $last ?>
        |
        <?php echo ($_SESSION['finished'])?>
      </p>
      <p class='smiling'>Session score:
        <?php echo ($_SESSION['score'])?>
      </p>
      <p class='smiling'>Student ID:
        <?php echo ($_SESSION['studentID'])?>
      </p>
  </div>
</div>
</body>
</html>